package es.udc.emarketapp.http.controller.actions.general;

import es.udc.emarketapp.http.view.actionForms.LocaleForm;
import es.udc.fbellas.j2ee.util.exceptions.InternalErrorException;
import es.udc.fbellas.j2ee.util.struts.action.DefaultAction;
import java.util.Locale;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;

    
public class SelectLocaleAction extends DefaultAction {

    public ActionForward doExecute(ActionMapping mapping,
        ActionForm form, HttpServletRequest request,
        HttpServletResponse response)
        throws IOException, ServletException, InternalErrorException {
        
        /* Get data. */
        LocaleForm localeForm = (LocaleForm) form;
        String language = localeForm.getLanguage();
        String country = localeForm.getCountry();
        
        /* Change locale. */
        System.out.println(language +" " +  country);

        Locale locale = new Locale(language, country);
        setLocale(request, locale);
       
        
        /* Return ActionForward. */
        return mapping.findForward("Welcome");
        
    }

}
